package com.mohan.json;

import org.json.JSONObject;

import com.mohan.util.WxLoginUtil;

public class WxLogin {
	public static boolean paserOpenId(String jsonStr, WxLoginUtil wxLoginUtil){
		System.out.println("jsonStr = " + jsonStr);
		
		JSONObject obj = new JSONObject(jsonStr);	
		if(obj.has("errcode")){
			int errcode = obj.getInt("errcode");
			if(errcode == 40029){
				System.out.println("wx code error.");
				return false;
			}else{
				return false;
			}
		}else{
			if (obj.has("openid")) {
				wxLoginUtil.setOpenid(obj.getString("openid"));
			}else{
				System.out.println("get openid tag error.");
				return false;
			}
			if(obj.has("session_key")){
				wxLoginUtil.setSession_key(obj.getString("session_key"));
			}else{
				System.out.println("get session_key tag error.");
				return false;
			}
			if(obj.has("UNIONID")){
				wxLoginUtil.setUnionid(obj.getString("UNIONID"));
			}else{
				wxLoginUtil.setUnionid("UNIONID");
			}
		}
		
		return true;		
	}
}
